<#include "/common/head.ftl">

<@showTitle title="${i18n.getMessage('user')} > ${i18n.getMessage('create_one')}">
</@showTitle>

<div id="error" style="display:none"></div>

<form action="user/addUser.sgt" validator="user/validateUser.sgt" onsubmit="submitAddUserForm(this); return false;" onreset="$('error').hide()">
	<table id="dataTable" align="center" cellspacing="5" cellpadding="0">
		<tr>
			<td class="name"><@required/>${i18n.getMessage('username')}:</td>
			<td><input type="text" name="username" style="width:200px"/> </td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('password')}:</td>
			<td><input type="password" name="password" style="width:200px"/> </td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('firstName')}:</td>
			<td><input type="text" name="firstName" style="width:200px"/> </td>
		</tr>
		<tr>
			<td class="name">${i18n.getMessage('lastName')}:</td>
			<td><input type="text" name="lastName" style="width:200px"/> </td>
		</tr>
		<tr>
			<td class="name">${i18n.getMessage('email')}:</td>
			<td><input type="text" name="email" style="width:200px"/></td>
		</tr>
		<tr>
			<td class="name">${i18n.getMessage('sites')}:</td>
			<td>
				<select name="sites" style="width:204px" multiple>
					<option></option>
					<#list sites as site>
						<option value="${(site.id)!}">${(site.name)!}</option>
					</#list>
				</select>
			</td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('roles')}:</td>
			<td>
				<select name="roles" style="width:204px" multiple>
					<#list roles as role>
						<option value="${(role.id)!}">${(role.name)!}</option>
					</#list>
				</select>
			</td>
		</tr>
		<tr>
			<td class="name" style="vertical-align:top">${i18n.getMessage('comment')}:</td>
			<td><textarea name="comment" style="width:350px;height:80px;"></textarea></td>
		</tr>
		<tr>
			<td class="name"></td>
			<td>
				<input type="submit" value="${i18n.getMessage('add')}" class="button_style"/> 
				<input type="reset" value="${i18n.getMessage('reset')}" class="button_style"/> 
			</td>
		</tr>
	</table>
</form>

<script>
	resetAddUserForm = function(type) {
		if(type == 'failure') {
			document.forms[0].password.value = '';
		}
	}

	submitAddUserForm = function(form) {
		var password = form.password.value;
		if(password != '') {
			form.password.value = hex_sha1(password);
		}
		submitFormValidation(form, '', 'POST', resetAddUserForm);
	}
	
	$('error').hide();
	document.forms[0].username.focus();
</script>